#include <iostream>
using namespace std;
class Base1 {
public:
    virtual void func1() { cout << "Base1::func1()" << endl; }
    virtual void func2() { cout << "Base1::func2()" << endl; }
};

class Base2 {
public:
    virtual void func1() { cout << "Base2::func1()" << endl; }
};

class Derive :public Base1,public Base2 {
public:
    virtual void func1() { cout << "Derive::fun1()" << endl; }
    virtual void func3() { cout << "Derive::func3()" << endl; }
};

typedef void(*VF_Ptr)() ;   //函数的重命名--函数指针   ---

void PrintVale(VF_Ptr vft[])   //传了一个函数指针数组
{
    for(int i=0;vft[i] !=nullptr;i++)   //windows下的虚表的结尾是以空指针进行结尾
    {
        printf("[%d]-->%p    ", i, vft[i]);
        vft[i]();
    }
    cout << endl;
}


int main()
{
    //Base b;
    //Derive d;

    //PrintVale((VF_Ptr*)(*(void **)&b));   //32位的    ///64位的机器下  //  32/64位下都能运行，void** 

    //PrintVale((VF_Ptr*)(*(void **)&d));

    Base1 b1;
    Base2 b2;
    Derive d;

    PrintVale((VF_Ptr*)(*(void**)&b1));

    PrintVale((VF_Ptr*)(*(void**)&b2));

    PrintVale((VF_Ptr*)(*(void**)&d));
   // PrintVale((VF_Ptr*)(*((void **)&d+sizeof(Base1))));   //行不通,这个是错误的
    //方法1 +偏移量
    PrintVale((VF_Ptr *)(*(void **)((char*)&d+sizeof(Base1))));
    //通过切片的方式
    Base2* ptr2 = &d;
    PrintVale((VF_Ptr*)(*(void**)ptr2));


    return 0;
}


